#!/bin/bash
#这个是mysql的卸载完整版


echo "开始清理MySQL..."

# 停止MySQL服务
echo "停止MySQL服务..."
systemctl stop mysqld 2>/dev/null || true
systemctl disable mysqld 2>/dev/null || true

# 卸载MySQL相关包
echo "卸载MySQL软件包..."
yum remove -y mysql-community-server mysql-community-client mysql-community-common mysql-community-libs mysql-community-devel 2>/dev/null || true
yum remove -y mysql-server mysql-client mysql-common mysql-libs 2>/dev/null || true

# 删除MySQL数据目录
echo "删除MySQL数据文件..."
rm -rf /var/lib/mysql
rm -rf /var/log/mysqld.log

# 删除MySQL配置文件
echo "删除MySQL配置文件..."
rm -f /etc/my.cnf
rm -f /etc/my.cnf.d/*
rm -f /etc/yum.repos.d/mysql57-community.repo
rm -f /etc/yum.repos.d/mysql57.repo

# 删除MySQL用户和组
echo "清理MySQL用户..."
userdel mysql 2>/dev/null || true
groupdel mysql 2>/dev/null || true

# 清理yum缓存
echo "清理yum缓存..."
yum clean all

# 删除临时文件
echo "删除临时文件..."
rm -f mysql57-community-release-el7-11.noarch.rpm 2>/dev/null || true

echo "MySQL清理完成！"
echo "系统已恢复到安装前的状态"
